
alist = [1, 2, 3, 4, 5, 6]

for i,j in enumerate(alist):
    print(i,j)

blist = alist[::-1]

print (blist)

clist = [x*2 for x in alist if x%2==0]
print (clist)


print(5*'abc')

mylist = []
mylist2 = mylist*3
print(mylist2)


board = [['-']*3 for i in range(3)]
board[1][2]='wangbo'
print(board)

weird_board = [['-']*3]*3
weird_board[1][2]='wangbo'
print(weird_board)


xa = range(3)
print(type(xa))

xb = ['a', 'b']
xb.extend(['bo'])
print(xb)

import bisect
import random

SIZE = 7
random.seed(1729)
my_list = []
for i in range(SIZE):
    new_item = random.randrange(SIZE*2)
    bisect.insort(my_list, new_item)
    print('%2d ->' % new_item, my_list)


from array import array
from random import random

# floats = array('d', (random() for i in range(10**7)))
# fp1 = open('floats.bin', 'wb')
# floats.tofile(fp1)

numbers = array('h',[-2, -1, 0, 1, 2])
print(numbers)

tt=(1, 2, (30, 40))
print(hash(tt))


DIAL_CODES = [(86, 'China'), (91, 'India')]
country_code = {country:code for code, country in DIAL_CODES}
print(country_code)
print({code: country.upper() for country, code in country_code.items() if code >90})

print(hex(1234))

L = (x*x for x in range(10))
print(L)
for i in L:
    print(i)


def char2num(a):
    abc = {str(a): a for a in range(10)}
    return abc[a]

from functools import reduce
def str2int(s):
    return reduce(lambda x, y: x*10 + y, map(char2num, s))

print(str2int('321'))


def _old_iter():
    n = 1
    while True:
        n = n + 2
        yield n

def _not_divisible(n):
    return lambda x: x%n > 0

def primes():
    yield 2
    it = _old_iter()
    while True:
        n = next(it)
        yield n
        it = filter(_not_divisible(n), it)

for n in primes():
    if n < 1000:
        print(n)
    else:
        break


import sys
print(sys.path)


class XClass(object):
    def __init__(self, stu_name):
        self.__name = stu_name
        self.__age = 10

    @property
    def age(self):
        return self.__age
    
    @age.setter
    def age(self, value):
        self.__age = value

    def __repr__(self):
        return 'My Instance is name->%s age->%d' % (self.__name, self.__age)

e = XClass('xuhua')
print(e.age)
e.age = 20
print(e)



from enum import Enum, unique

@unique
class Weekday(Enum):
    Sun = 0 # Sun的value被设定为0
    Mon = 1
    Tue = 2
    Wed = 3
    Thu = 4
    Fri = 5
    Sat = 6

bb = Weekday.Mon
print(isinstance(bb, Enum), type(bb))


#assert 0, 'zero by'

class baseClass(object):
    num = 0
    num_list = []

    def __init__(self, my_name):
        self.name = my_name

vv1 = baseClass('wangbo')
vv2 = baseClass('dongwei')

print(vv1.__dict__)
print(baseClass.__dict__)

vv1.num = 5
vv1.num_list.append(5)

print(vv1.__dict__)
print(baseClass.__dict__)

baseClass.gender = 'man'

print(vv1.__dict__)
print(baseClass.__dict__)
print(vv1.gender)